package uk.co.hs.property.editors;

import java.beans.PropertyEditorSupport;

/**
 */
public class ClassPropertyEditor extends PropertyEditorSupport
{
  public ClassPropertyEditor()
  {}

  /**
   * @see java.beans.PropertyEditorSupport
   * #setAsText(java.lang.String)
   */
  @Override
  public void setAsText(String aText) throws IllegalArgumentException
  {
    if (aText == null || aText.equals("")) return;
    try
    {
      setValue(Class.forName(aText));
    }
    catch (ClassNotFoundException aException)
    {

    }
  }

  /**
   * @see java.beans.PropertyEditorSupport
   * #getAsText()
   */
  @Override
  @SuppressWarnings("rawtypes")
  public String getAsText()
  {
    if (getValue() == null) return null;

    Class clazz = (Class) getValue();
    return clazz.getCanonicalName();
  }
}
